<?php 
// No direct access
defined ('_JEXEC') or die();

jimport ('joomla.application.component.controllerform');

class ShipnhanhControllerEmailhelper extends JControllerForm
{
	
	public function __construct($config = array())
	{
		parent::__construct($config);
	}
	
	public function sendMail()
	{
		$app = JFactory::getApplication();
		$items = $app->getUserState($this->option . '.sendmail');
		$app->setUserState($this->option . '.sendmail', null);
		
		JRequest::setVar('items', $items);
		JRequest::setVar('view', 'emailhelper');
		$this->display();
	}
	
	public function doSend()
	{
		$body = JRequest::getVar( 'email_content', '', 'post', 'string', JREQUEST_ALLOWRAW );
		
		$mailer = JFactory::getMailer();
		$config = JFactory::getConfig();
		$sender = array($config->getValue('config.mailfrom'), $config->getValue('config.mailto'));
		
		$mailer->setSender($sender);
		$user = JFactory::getUser();
		$mailer->addRecipient(JRequest::getVar('email_to', 'post'));
		
		$mailer->isHTML(true);
		$mailer->Encoding = 'base64';
		$mailer->setBody($body);
		$mailer->setSubject(JRequest::getVar('email_subject', 'post'));
		
 		$send =& $mailer->Send();
 		if ( $send !== true ) {
 			echo 'Error sending email: ' . $send->message;
 		} else {
 			echo 'Mail sent';
 		}
	}
	
	public function cancel()
	{
		$cid = JRequest::getVar('cid', 'post', 'array');
		echo 's=' . count($cid);
		$app = JFactory::getApplication();
		$app->setUserState('ids', $cid);
		$url = JFactory::getURI();
		$this->setRedirect($url . '?option=' . $this->option . '&task=order.billout');
	}
}
?>